package org.example

object scalaFunData1 {
  def main(args: Array[String]): Unit = {

    def func1: Int => Int = (i: Int) => i * 2

    val list1 = List(1, 2, 3, 4, 5).map(func1)
    println(list1)
    val s = "scala"
    println(s.toUpperCase)

    val func2 = (word: String) => word.toUpperCase
    val wordList = List("java", "scala", "python")
    //val result = wordList.map(func2)
    val result = wordList.map(_.toUpperCase)

    println(result)
    val numList = List(20, 50, 70)
    numList.map(t => println(t * 2))
    println(numList.head)
    println(numList.tail)
    println(numList.max)
    println(numList.sum)
    val exam = Array(("张三", Array(58, 69, 72, 88)), ("李四", Array(49, 66, 77, 88)))
    exam.map(tp => (tp._1, tp._2.max)).foreach(println)
    exam.map(tp => (tp._1, tp._2.count(_ >= 60))).foreach(println)

    val arr1 = Array(1, 2, 3, 4, 5, 6)
    arr1.filter(t => if (t % 2 == 0) true else false).foreach(println)
    arr1.filter(t => t % 2 == 0).foreach(println)
    arr1.filter(_ % 2 == 0).foreach(println)

    val arr2 = Array(Array(1,2,3),Array(3,6,9))
    arr2.flatten.foreach(println)
    val arr3 = Array("a b c","d e f ")
    println("==========")
    arr3.flatMap(t => t.split("")).foreach(println)
    println("==========")
    val arr4 = Array(("a","b"),("c","d"))
    arr4.flatMap(t => Array(t._1,t._2)).foreach(println)
    val arr5 = Array("张三 60 70 80","李四 50 70 90")
    arr5.map(t => t.split(" ")).flatMap((arr5 => arr5.tail.map(t => (arr5.head, t)))).foreach(println)
    println("==========")
  }
}
